package com.hd.tiyu.yuejian.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.tiyu.yuejian.JavaBean.Contest;
import com.hd.tiyu.yuejian.Model.ListsModel;
import com.hd.tiyu.yuejian.R;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MatchDetailActivity extends AppCompatActivity {
    private ImageView back,img_matchdetail;
    private TextView matchname;
    private TextView introduntion;
    private TextView matchdate;
    private TextView dizhi;
    private TextView hits;
    private TextView update_time;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.match_detail);
        initViews();
        initData();
        initEvents();
    }

    private void initViews() {
        back=(ImageView) findViewById(R.id.img_match_detail_back);
        img_matchdetail=(ImageView)findViewById(R.id.img_match_photo);

        matchname=(TextView)findViewById(R.id.tex_matchtitle);
        introduntion=(TextView)findViewById(R.id.tex_introdution);
        matchdate=(TextView)findViewById(R.id.text_cdate);
        dizhi=(TextView)findViewById(R.id.tex_url);
        hits=(TextView)findViewById(R.id.tex_hits);
        update_time=(TextView)findViewById(R.id.tex_bisai_updatetime);

    }

    private void initData() {
        Intent intent=getIntent();
        String Matchid=intent.getStringExtra("id");
        //String Matchid=intent.getStringExtra("id");
                ListsModel listModel=new ListsModel();
        Call<Contest> call=listModel.getMatchDetail(Matchid);
        call.enqueue(new Callback<Contest>() {
            @Override
            public void onResponse(Call<Contest> call, Response<Contest> response) {
                Contest data=response.body();
                matchname.setText(data.getName());
                introduntion.setText(data.getIntroduction());
                matchdate.setText(data.getCdate());
                dizhi.setText(data.getUrl());
                hits.setText(data.getHits());
                update_time.setText(data.getUpdate_time());
                Picasso.with(MatchDetailActivity.this)
                        .load("http://172.24.10.175/workout/Uploads/"+data.getThumb())
                        .resize(1200,450).centerCrop()
                        .into(img_matchdetail);
            }

            @Override
            public void onFailure(Call<Contest> call, Throwable t) {

            }
        });

    }

    private void initEvents() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
